<?php

//用户注册
include_once '../../library/config.php';
include_once '../../model/userlist.php';

$list = new UserList();
$entity = new UserList();
$entity->request();

try {
    if (!preg_match("/^1[34578]\d{9}$/", $entity['account'])) {
        throw new Exception("101"); //匹配手机号格式
    }
    if (!preg_match("/(?!^\d+$)(?!^[a-zA-Z]+$)[0-9a-zA-Z]{6,12}/", $entity['pwd'])) {
        throw new Exception("102"); //匹配密码格式
    }
    if ($list->select("myid")->where("account=" . $entity['account'])->get_first_rows()) {
        throw new Exception("103"); //帐号查重
    }
    $entity->keyvalue("shijian", time());
    $entity->keyvalue('pwd', md5($entity['account'] . $entity['pwd']));
    $entity->remove(array('signtoken'));
    $entity->append()->submit(); //提交注册用户信息
    $entity->keyvalue("myid", $entity->autoid);
} catch (Exception $ex) {
    $entity->rsscode($ex);
}

$entity->keyvalue("usertoken", md5($entity['account'] . $entity['myid']));
$entity->remove(array('pwd')); //返回值删除密码
$entity->remove(array('shijian')); //返回值删除密码
echo $entity->toJson();
